package com.acme.bankapp.domain;
import com.acme.bankapp.domain.Account;

public class CheckingAccount extends Account {
	private double balance;
	private double overdraft;
	CheckingAccount(double startBalance, double startOverdraft) {
		super();
		this.balance = startBalance;
		this.overdraft = startOverdraft;
	}
	@Override
	void deposite(double delta) {
		this.balance += delta;
	}
	@Override
	void withdraw(double delta) {
		if (this.balance >= delta)
			this.balance -= delta;
		else 
			if (this.overdraft >= (delta - this.balance)) {
				this.overdraft -= delta - this.balance;
				this.balance = 0;
			}
			else {
				this.balance -= delta - this.overdraft;
				this.overdraft = 0;
			}
	}
	@Override
	double getBalance() {
		return this.balance;
	}
	@Override
	double maxCredit() {
		if (this.balance <= 0)
			return this.overdraft;
		else
			return this.balance + this.overdraft;
	}
}
